/*
 * UiUtil.cpp
 *
 *  Created on: 2012-10-17
 *      Author: yangentao@gmail.com
 */

#include "UiUtil.h"



//32bit color
//must assign the first and last color,  colors[0] and colors[length-1]
//length >2
void transformColor(DWORD colors[], int length) {
	if (colors && length <= 2) {
		return;
	}
	DWORD colorFirst = colors[0];
	DWORD colorLast = colors[length - 1];
	BYTE r0 = GetRValue(colorFirst);
	BYTE g0 = GetGValue(colorFirst);
	BYTE b0 = GetBValue(colorFirst);
	BYTE r1 = GetRValue(colorLast);
	BYTE g1 = GetGValue(colorLast);
	BYTE b1 = GetBValue(colorLast);

	float deltaR = (r1 - r0) * 1.0f / (length - 1);
	float deltaG = (g1 - g0) * 1.0f / (length - 1);
	float deltaB = (b1 - b0) * 1.0f / (length - 1);

	BYTE r = 0;
	BYTE g = 0;
	BYTE b = 0;
	for (int i = 1; i < length - 1; ++i) {
		r = r0 + BYTE(deltaR * i + 0.5f);
		g = g0 + BYTE(deltaG * i + 0.5f);
		b = b0 + BYTE(deltaB * i + 0.5f);
		colors[i] = RGB(r, g, b);
	}
}

